package com.study.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class CompanyProxy implements InvocationHandler{
	
	private Object factory;
	
	public CompanyProxy(Object factory) {
		super();
		this.factory = factory;
	}





	public  Object getInvokeHandler() {
		return Proxy.newProxyInstance(factory.getClass().getClassLoader(), factory.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		doBefore();
		Object factotyUse=method.invoke(factory, args);
		doAfter();
		return factotyUse;
	}
	
	private void doBefore() {
		System.out.println("市场调研");
	}
	
	private void doAfter() {
		System.out.println("市场抽样");
	}

}
